package com.share.servlet;

import lombok.SneakyThrows;

import javax.servlet.*;
import java.io.IOException;

/*
    1、servlet实例默认为懒加载
    2、请求到达时，构造servlet实例--->init方法（生命周期中只执行一次）--->service方法
 */
public class Servlet1 implements Servlet {

//    int count;
    Integer count;

    public Servlet1() {
        count = 0;
        System.out.println("servlet1---构造方法");
    }

    @SneakyThrows
    @Override
    public void service(ServletRequest servletRequest, ServletResponse servletResponse) throws ServletException, IOException {
        System.out.println("service方法：hello  servlet1" + count++);
        System.out.println("当前线程："+ Thread.currentThread().getName());
//        Thread.sleep(Integer.MAX_VALUE);
    }

    @Override
    public void init(ServletConfig servletConfig) throws ServletException {
        System.out.println("servlet1---init方法");
    }

    @Override
    public ServletConfig getServletConfig() {
        return null;
    }

    @Override
    public String getServletInfo() {
        return null;
    }

    @Override
    public void destroy() {
        System.out.println("destory方法");

    }
}
